<?
require_once 'clogin.inc.php';
require_once 'admin_head.php';
?>

<? 
$model_name ='通讯录';
if ($_POST['action'] == 'edit'){
	$id = intval($_POST['id']);
	$who = $_POST['who'];
	$mobile = $_POST['mobile'];
	$xiao = $_POST['xiao'];
	$qq = $_POST['qq'];
	$email = $_POST['email'];
	$msn = $_POST['msn'];
	$office = $_POST['office'];
	$home = $_POST['home'];
	$cid = $_POST['cid'];	
	$info = $_POST['info'];
	$displayid = $_POST['displayid'];
	$update_time = time();
	
	empty($displayid) ? $displayid = 0 : 0;
	$uid = $_SESSION["uid"];
/*	echo $id;
	echo $sitename;
	echo $url;
	echo $info;
	echo $displayid;*/

	if (empty($id)) {
		$sql = "INSERT INTO {$tablepre}adds (who, mobile, xiao, qq, email, msn, office, home, info, displayid,cid,uid,create_time,update_time) 
				VALUES('$who', '$mobile', '$xiao', '$qq', '$email', '$msn', '$office', '$home', '$info', $displayid,$cid,'$uid','$update_time','$update_time')";
		$edit = '添加';		
	}else{
		$sql = "UPDATE {$tablepre}adds SET
		 who = '$who', mobile = '$mobile', xiao = '$xiao', qq = '$qq', email = '$email', msn = '$msn', office = '$office', home = '$home', info = '$info', displayid = $displayid, cid = $cid ,update_time='$update_time'
		 WHERE id = $id LIMIT 1";
	
		$edit = '修改';	
	} 
	mysql_query($sql); 	

	if ( mysql_affected_rows() == 1 ) {
		if(mysql_insert_id()) $id = mysql_insert_id();
		 showmsg("{$model_name}{$edit}成功！",'成功',"?id=$id",'返回');
		
	}else{
		 showmsg("{$model_name}{$edit}失败或没有修改！",'失败',"return",'返回');
	}
	
}
if ($_GET['id']) {
	$id = intval($_GET['id']);
	if ($_GET['action'] == 'del'){
		$edit = '删除';	
		$sql = "DELETE FROM {$tablepre}adds WHERE id = $id LIMIT 1";
		mysql_query($sql);
		showmsg("{$model_name}{$edit}成功！",'成功',"../frmView_right.php",'返回');
		exit();
		
	}
	$sql = "SELECT * FROM {$tablepre}adds WHERE id = $id ";
	$result=mysql_query($sql); 
	$eadds = mysql_fetch_array($result);
}
?>

<p>&nbsp;</p>

<div class="edit">
<div class="title"><?php 
if ($_GET['id']) {
	echo "编辑： $eadds[who]  信息 [<a href=\"admin_adds.php\">添加一个新的</a>]";
}else{
	echo "添加联系人";
}
?></div>
<form id="form1" name="form1" method="post" action="">

<input name="action" type="hidden" value="edit" />
<input name="id" type="hidden" value="<? echo $eadds['id'] ?>" />
		<table>
          <tr>
            <td align="right" nowrap="nowrap"> 名称：</td>
            <td><input type="text" name="who" size="16" value="<? echo $eadds['who'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> 手机：</td>
            <td><input type="text" name="mobile" size="16" value="<? echo $eadds['mobile'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> 小灵通：</td>
            <td><input type="text" name="xiao" size="16" value="<? echo $eadds['xiao'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> email：</td>
            <td><input type="text" name="email" size="32" value="<? echo $eadds['email'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> qq：</td>
            <td><input type="text" name="qq" size="16" value="<? echo $eadds['qq'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> msn：</td>
            <td><input type="text" name="msn" size="32" value="<? echo $eadds['msn'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> 办公电话：</td>
            <td><input type="text" name="office" size="16" value="<? echo $eadds['office'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> 住宅电话：</td>
            <td><input type="text" name="home" size="16" value="<? echo $eadds['home'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> 备注：</td>
            <td><input type="text" name="info" size="48" value="<? echo $eadds['info'] ?>" /></td>
          </tr>
          <tr>
            <td align="right" nowrap="nowrap"> 显示顺序：</td>
            <td><input name="displayid" type="text"   value="<? echo $eadds['displayid'] ?>" size="5" />
              数越小排序越靠前</td>
          </tr>
          <tr>
            <td >分组：</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td >文件夹：</td>
            <td><input name="cid" type="text" id="cid"   value="15" size="5" /></td>
          </tr>
          <tr>
            <td ></td>
            <td><input name="submis" type="submit" value="确定" /></td>
          </tr>
        </table>
        <p>&nbsp;</p>
</form></div>
<p>&nbsp;</p>
</body>
</html>